import time

import requests
from config.config import *

def send_feishu_msg():
    message_data = [
        [
            {
                "tag":"text",#文本内容
                "text":f"项目名称：{PROJECT}"
            }
        ],
        [
            {
                "tag": "text",  # 文本内容
                "text": f"执行时间：{time.strftime('%Y-%m-%d %H-%M-%S')}"
            }
        ],
        [
            {
                "tag":"text",
                "text":"详细信息："
            },
            {
                "tag":"a",#超链接
                "text":"查看测试报告",
                "href":"https://www.baidu.com/"
            }
        ]
    ]
    payload = {
        "msg_type":"post",
        "content":{
            "post":{
                "zh_cn":{
                    "title":"自动化测试报告",
                    "content":message_data
                }
            }
        }
    }
    #判断发送消息的开关
    if FEISHU_IS_SEND:
        response = requests.post(WEBHOOK,json=payload)
        return response

if __name__ == '__main__':
    send_feishu_msg()


#步骤1导入requests
# import requests

#步骤2 定义webhook地址
# webHook = "https://open.feishu.cn/open-apis/bot/v2/hook/f768937c-b4c5-405b-8e89-a1e14ee38aa4"

#步骤3 构造富文本消息
# message_data = [
#     [
#         {
#              "tag":"text",#文本内容
#             "text":"星云ERP"
#         }
#     ],
#     [
#         {
#             "tag":"a",#超链接
#             "text":"查看测试报告",
#             "href":"https://www.baidu.com/"
#         }
#     ]
# ]

#步骤4 构建最终的消息体
# payload = {
#     "msg_type":"post",
#     "content":{
#         "post":{
#             "zh_cn":{
#                 "title":"自动化测试报告",
#                 "content":message_data
#             }
#         }
#     }
# }
#步骤5 发送消息
# response = requests.post(webHook,json=payload)
# print(response)
# print(response.text)